package cn.com.victorysoft.ylgl.service.fracturingpressure.controller.jobTest;

import cn.com.victorysoft.ylgl.service.commons.mybatis.paging.bean.DataPaging;
import cn.com.victorysoft.ylgl.service.commons.web.JsonMessage;
import cn.com.victorysoft.ylgl.service.commons.web.RequestContext;
import cn.com.victorysoft.ylgl.service.commons.web.User;
import cn.com.victorysoft.ylgl.service.fracturingpressure.domain.jobTest.BackRowDataEntity;
import cn.com.victorysoft.ylgl.service.fracturingpressure.service.jobTest.IBackRowDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 返排数据控制器
 */
@Controller
@RequestMapping({"JobTest/backRowData"})
public class BackRowDataController {
    private static final Logger logger = LoggerFactory.getLogger(BackRowDataController.class);

    @Resource
    private IBackRowDataService service;

    public BackRowDataController() {
    }

    @RequestMapping(
            value = {"/list.wet"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    public String list() {
        return "backRowData/list";
    }

    @RequestMapping(
            value = {"/add/save.wds"},
            method = {RequestMethod.POST}
    )
    @ResponseBody
    public JsonMessage createEntity(@ModelAttribute("backRowDataEntity") BackRowDataEntity entity) {
        User user = RequestContext.getCurrentUser();
        //entity.setCjr(user.getName());
        //entity.setCjrq(new Date());
        /*
        try {
            MultipartFile mf = entity.getBgfjFile();
            String relativeFile = "";
            if ((mf != null)&&(mf.getSize()>0)) {
                relativeFile = DocumentFileHelper.saveFile(DocumentFileHelper.getDocumentRootPath(),FailureAnaRepController.DocDirectoryName,mf);
                entity.setBgfjlj(relativeFile);
                entity.setBgfj(mf.getOriginalFilename());
            }
        } catch (IllegalStateException e) {
            e.printStackTrace();
            return new JsonMessage().failure(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            return new JsonMessage().failure(e.getMessage());
        }

        this.curService.insert(entity);
        FailureAnaRepVO newEntity = curService.getDtoBy(entity.getSxbgid());
        return (new JsonMessage()).success(newEntity);
        */
        return (new JsonMessage()).success("实体");
    }


    @RequestMapping(
            value = {"/update/save.wds"},
            method = {RequestMethod.POST}
    )
    @ResponseBody
    public JsonMessage updateEntity(@ModelAttribute("backRowDataEntity") BackRowDataEntity entity) {
        //先根据faid查以前方案的信息
        /*
        FailureAnaRep oldEntity = curService.get(entity.getSxbgid());
        //用户需要覆盖以前的文档
        if(oldEntity!=null){
            doHistoricalData(oldEntity,entity);
        }

        User user = RequestContext.getCurrentUser();
        entity.setCjr(user.getName());
        entity.setCjrq(new Date());
        try {
            MultipartFile mf = entity.getBgfjFile();
            String relativeFile = "";
            if (mf != null) {
                if(mf.getSize()>0){
                    relativeFile = DocumentFileHelper.saveFile(DocumentFileHelper.getDocumentRootPath(),FailureAnaRepController.DocDirectoryName,mf);
                    entity.setBgfjlj(relativeFile);
                    entity.setBgfj(mf.getOriginalFilename());
                }else{
                    entity.setBgfjlj("");
                    entity.setBgfj("");
                }

            }
        } catch (IllegalStateException e) {
            e.printStackTrace();
            return new JsonMessage().failure(e.getMessage());
        } catch (IOException e) {
            e.printStackTrace();
            return new JsonMessage().failure(e.getMessage());
        }
        if(oldEntity!=null){
            this.curService.update(entity);
        }
        else{
            this.curService.insert(entity);
        }
        FailureAnaRepVO newEntity = curService.getDtoBy(entity.getSxbgid());

        return (new JsonMessage()).success(newEntity);
        */
        return (new JsonMessage()).success("实体");
    }

    @RequestMapping(value={"/delete.wds"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}, produces={"application/json;charset=UTF-8"})
    @ResponseBody
    public JsonMessage delete(@RequestParam(value="keyValue", required=true) String keyValue)
    {
        try
        {
            /*
            FailureAnaRep entity = this.curService.get(sxbgid);
            if(entity!=null)
            {
                this.curService.delete(sxbgid);
                doDeleteFileData(entity);
            }
            */
            return new JsonMessage().success();
        }
        catch (Exception e)
        {
            logger.error("删除出错: {}", e);
        }
        return new JsonMessage().failure("失败");
    }

    @RequestMapping(
            value = {"/queryPagingList.wds"},
            method = {RequestMethod.GET, RequestMethod.POST}
    )
    @ResponseBody
    public JsonMessage queryList(@RequestParam(value = "page",required = false) String page,
                                 @RequestParam(value = "rows",required = false) String rows,
                                 @RequestParam(value = "yt",required = false) String yt,
                                 @RequestParam(value = "qk",required = false) String qk,
                                 @RequestParam(value = "dk",required = false) String dk,
                                 @RequestParam(value = "cw",required = false) String cw,
                                 @RequestParam(value = "jh",required = false) String jh,
                                 @RequestParam(value = "startDate",required = false) String startDate,
                                 @RequestParam(value = "endDate",required = false) String endDate) {
        /*
        DataPaging<BackRowDataEntity> dataPaging =  this.curService.queryList(dw,dy,jh,sxyy,startDate,endDate, rows,page);
        */
        DataPaging<BackRowDataEntity> dataPaging =  new DataPaging<>(null,0);
        return (new JsonMessage()).success(dataPaging);
    }

}
